home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Shell ƒ / sounds.c < prev    next >
Text File  |  1994-04-15  |  2KB  |  94 lines

  1. /**********************************************************************\
  2.  
  3. File:        sounds.c
  4.  
  5. Purpose:    This module handles playing syncronous and asyncronous
  6.             sounds.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "sounds.h"
  26.  
  27. SndChannelPtr        myChannel;
  28. Handle                MySounds[NUM_SOUNDS];
  29. Boolean                gSoundToggle;
  30. Boolean                gSoundAvailable;
  31.  
  32. pascal void SoundIsComplete(SndChannelPtr theChannel, SndCommand theCmd);
  33.  
  34. void InitTheSounds(void)
  35. {
  36.     int                i;
  37.     
  38.     gSoundAvailable=(SndNewChannel(&myChannel, 0, 0L, 0L)==noErr);
  39.     if (gSoundAvailable)
  40.         SndDisposeChannel(myChannel, TRUE);
  41.     myChannel=0;
  42.     for (i=0; i<NUM_SOUNDS; i++)
  43.         MySounds[i]=0L;
  44. }
  45.  
  46. void DoSound(int whichSound, Boolean async)
  47. {
  48.     SndCommand            myCommand;
  49.     
  50.     if (myChannel!=0)
  51.     {
  52.         SndDisposeChannel(myChannel, TRUE);
  53.         myChannel=0;
  54.     }
  55.     
  56.     whichSound-=1000;
  57.     if ((gSoundToggle) && (gSoundAvailable))
  58.     {
  59.         if (!MySounds[whichSound])
  60.             MySounds[whichSound]=GetResource('snd ', whichSound+1000);
  61.         
  62.         if (MySounds[whichSound])
  63.         {
  64.             if (SndNewChannel(&myChannel, 0, 0L, (ProcPtr)SoundIsComplete) != noErr)                    
  65.             {
  66.                 myChannel = 0;
  67.                 gSoundAvailable = FALSE;
  68.             }
  69.             else
  70.             {
  71.                 SndPlay(myChannel, MySounds[whichSound], async);
  72.                 if (async)
  73.                 {
  74.                     myCommand.cmd=callBackCmd;
  75.                     myCommand.param1=myCommand.param2=0;
  76.                     SndDoCommand(&myChannel, &myCommand, false);
  77.                 }
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. pascal void SoundIsComplete(SndChannelPtr theChannel, SndCommand theCmd)
  84. {
  85.     SndDisposeChannel(myChannel, TRUE);
  86.     myChannel=0;
  87. }
  88.  
  89. void ShutDownTheSounds(void)
  90. {
  91.     if (myChannel)
  92.         SndDisposeChannel(myChannel, TRUE);
  93. }
  94.